local dir `c(pwd)'
local g=`1'
qui {
clear
set obs 1
foreach type in original order structure {
gen entropy_`type'=.
gen words_`type'=.
gen chars_`type'=.
}
gen book=.             
gen str translation=""	                        
save  entropy_bible_`g', replace

use calculation_`g', clear

local till=_N
local counter=_N

forvalues i=1/`till' {
	use calculation_`g', clear
	local translation=translation[`i']
	local samplesize_chars=samplesize_chars[`i']
	local book=book[`i']
	local counter=`counter'-1
	use "`dir'\\corpus\\`translation'.dta" , clear
	drop if sentence==""
	
	noisily di "`translation' (left: `counter' | book: `book') "
		
		foreach type in original order structure {					
			use `"`dir'\\stata_files\length_`translation'_`book'_`type'"', clear
			/* constant string size in chars*/
			drop if _n>`samplesize_chars'
			local chars_`type'_`book'=_N
			gen words=1 if v1==" "
			sum words if words==1
			local words_`type'_`book'=r(N)
			ren v2 li
			gen i=_n
			local n=_N
			gen tosum=(li)/(log(i)/log(2))
			sum tosum
			local entropy_`type'_`book'=r(sum)
		}			
		use  entropy_bible_`g', clear
					local new=_N+1
					set obs `new'
					local in `"in `new'"'
					foreach type in original order structure {
							replace entropy_`type'=`entropy_`type'_`book'' 	`in'
							replace chars_`type'=`chars_`type'_`book'' 			`in'
							replace words_`type'=`words_`type'_`book'' 			`in'
							}   
					replace book=`book'                     			`in'      		
					replace translation="`translation'"	          	`in'  
					save  entropy_bible_`g', replace
				}
			}
/* generate finished file */
clear
set obs 1
gen v=1
save finished_`g', replace


clear         
exit, STATA 	
